import request from '@/utils/request'

// 用户认证相关接口
export const authApi = {
  // 用户登录
  login(data) {
    return request.post('/user/login', data)
  },
  
  // 用户注册
  register(data) {
    return request.post('/user/register', data)
  },
  
  // token验证
  verifyToken(token) {
    return request.get(`/user/verify/${token}`)
  },
  
  // 获取用户完整信息
  getUserInfo(token) {
    return request.get(`/user/getUserInfo/${token}`)
  },
  
  // 用户登出
  logout() {
    return request.get('/user/logout')
  },
  
  // 忘记密码
  forgetPassword(data) {
    return request.post('/user/forgetPassword', data)
  },
  
  // 获取角色列表
  getRoleList(data) {
    return request.post('/role/getRoleList', data)
  }
}

// 文件上传相关接口
export const uploadApi = {
  // 上传图片
  uploadImage(file, type = 'image') {
    const formData = new FormData()
    formData.append('file', file)
    formData.append('type', type)
    return request.post('/api/upload/image', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },
  
  // 上传视频
  uploadVideo(file, type = 'video') {
    const formData = new FormData()
    formData.append('file', file)
    formData.append('type', type)
    return request.post('/api/upload/video', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },
  
  // 上传文件
  uploadFile(file, type = 'file') {
    const formData = new FormData()
    formData.append('file', file)
    formData.append('type', type)
    return request.post('/api/upload/file', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  }
}

// 仪表盘相关接口
export const dashboardApi = {
  // 获取仪表盘统计数据
  getStatistics() {
    return request.get('/admin/dashboard/statistics')
  },
  
  // 获取最近活动列表
  getRecentActivities() {
    return request.get('/admin/dashboard/recent-activities')
  },
  
  // 获取系统状态信息
  getSystemStatus() {
    return request.get('/admin/dashboard/system-status')
  },
  
  // 获取用户趋势数据
  getUserTrend() {
    return request.get('/admin/dashboard/user-trend')
  },
  
  // 获取展商趋势数据
  getExhibitorTrend() {
    return request.get('/admin/dashboard/exhibitor-trend')
  },
  
  // 获取观众趋势数据
  getVisitorTrend() {
    return request.get('/admin/dashboard/visitor-trend')
  }
}

// 首页管理相关接口
export const homepageApi = {
  // 根据内容类型查询内容列表
  getContentByType(contentType) {
    return request.get(`/admin/homepage/content/${contentType}`)
  },
  
  // 获取所有有效的首页内容
  getAllActiveContent() {
    return request.get('/admin/homepage/content/all')
  },
  
  // 添加首页内容
  addContent(data) {
    return request.post('/admin/homepage/content', data)
  },
  
  // 更新首页内容
  updateContent(data) {
    return request.put('/admin/homepage/content', data)
  },
  
  // 删除首页内容
  deleteContent(id) {
    return request.delete(`/admin/homepage/content/${id}`)
  },
  
  // 批量删除首页内容
  deleteContents(ids) {
    return request.delete('/admin/homepage/content/batch', { data: ids })
  },
  
  // 更新内容状态
  updateContentStatus(id, status) {
    return request.put(`/admin/homepage/content/${id}/status?status=${status}`)
  },
  
  // 更新内容排序
  updateContentSort(sortData) {
    return request.put('/admin/homepage/content/sort', sortData)
  }
}

// 展商管理相关接口
export const exhibitorApi = {
  // 分页查询展商列表
  getExhibitorPage(params) {
    return request.get('/admin/exhibitor/page', { params })
  },
  
  // 获取展商详情
  getExhibitorById(id) {
    return request.get(`/admin/exhibitor/${id}`)
  },
  
  // 添加展商
  addExhibitor(data) {
    return request.post('/admin/exhibitor', data)
  },
  
  // 更新展商信息
  updateExhibitor(data) {
    return request.put('/admin/exhibitor', data)
  },
  
  // 删除展商
  deleteExhibitor(id) {
    return request.delete(`/admin/exhibitor/${id}`)
  },
  
  // 批量删除展商
  deleteExhibitors(ids) {
    return request.delete('/admin/exhibitor/batch', { data: ids })
  },
  
  // 审核展商申请
  auditExhibitor(id, status, comment, auditUser) {
    return request.put(`/admin/exhibitor/${id}/audit`, null, {
      params: { status, comment, auditUser }
    })
  },
  
  // 获取展商统计数据
  getStatistics() {
    return request.get('/admin/exhibitor/statistics')
  },
  
  // 获取待审核展商列表
  getPendingExhibitors() {
    return request.get('/admin/exhibitor/pending')
  },
  
  // 根据行业统计展商数量
  getExhibitorCountByIndustry() {
    return request.get('/admin/exhibitor/statistics/industry')
  }
}

// 展商产品管理相关接口
export const exhibitorProductApi = {
  // 分页查询产品列表（支持跨展商查询）
  getProductPage(exhibitorId, params) {
    if (exhibitorId) {
      return request.get(`/admin/exhibitor/product/page/${exhibitorId}`, { params })
    } else {
      return request.get('/admin/exhibitor/product/page', { params })
    }
  },
  
  // 获取产品详情
  getProductById(id) {
    return request.get(`/admin/exhibitor/product/${id}`)
  },
  
  // 添加产品
  addProduct(data) {
    return request.post('/admin/exhibitor/product', data)
  },
  
  // 更新产品信息
  updateProduct(data) {
    return request.put('/admin/exhibitor/product', data)
  },
  
  // 删除产品
  deleteProduct(id) {
    return request.delete(`/admin/exhibitor/product/${id}`)
  },
  
  // 批量删除产品
  deleteProducts(ids) {
    return request.delete('/admin/exhibitor/product/batch', { data: ids })
  },
  
  // 获取展商推荐产品列表
  getFeaturedProducts(exhibitorId) {
    return request.get(`/admin/exhibitor/product/featured/${exhibitorId}`)
  },
  
  // 更新产品推荐状态
  updateFeaturedStatus(id, isFeatured) {
    return request.put(`/admin/exhibitor/product/${id}/featured`, null, {
      params: { isFeatured }
    })
  },
  
  // 更新产品排序
  updateSortOrder(id, sortOrder) {
    return request.put(`/admin/exhibitor/product/${id}/sort`, null, {
      params: { sortOrder }
    })
  }
}

// 观众管理相关接口
export const visitorApi = {

  // 更新已读状态
  updateReadStatus(id) {
    return request.post(`/admin/visitor/updateReadStatus?id=${id}`,)
  },

  // 分页查询观众列表
  getVisitorPage(params) {
    return request.get('/admin/visitor/page', { params })
  },
  
  // 获取观众详情
  getVisitorById(id) {
    return request.get(`/admin/visitor/${id}`)
  },
  
  // 添加观众
  addVisitor(data) {
    return request.post('/admin/visitor', data)
  },
  
  // 更新观众信息
  updateVisitor(data) {
    return request.put('/admin/visitor', data)
  },
  
  // 删除观众
  deleteVisitor(id) {
    return request.delete(`/admin/visitor/${id}`)
  },
  
  // 批量删除观众
  deleteVisitors(ids) {
    return request.delete('/admin/visitor/batch', { data: ids })
  },
  
  // 获取观众统计数据
  getStatistics() {
    return request.get('/admin/visitor/statistics')
  },
  
  // 根据来源统计观众数量
  getVisitorCountBySource() {
    return request.get('/admin/visitor/statistics/source')
  },
  
  // 根据行业统计观众数量
  getVisitorCountByIndustry() {
    return request.get('/admin/visitor/statistics/industry')
  },
  
  // 根据地区统计观众数量
  getVisitorCountByRegion() {
    return request.get('/admin/visitor/statistics/region')
  }
}

// 活动管理相关接口
export const activityApi = {
  // 分页查询活动列表
  getActivitiesPage(params) {
    return request.get('/admin/activity/page', { params })
  },
  
  // 获取活动详情
  getActivityById(id) {
    return request.get(`/admin/activity/${id}`)
  },
  
  // 添加活动
  addActivity(data) {
    return request.post('/admin/activity', data)
  },
  
  // 更新活动信息
  updateActivity(data) {
    return request.put('/admin/activity', data)
  },
  
  // 删除活动
  deleteActivity(id) {
    return request.delete(`/admin/activity/${id}`)
  },
  
  // 批量删除活动
  deleteActivities(ids) {
    return request.delete('/admin/activity/batch', { data: ids })
  },
  
  // 更新活动状态
  updateActivityStatus(id, status) {
    return request.put(`/admin/activity/${id}/status`, { status })
  },
  
  // 发布活动
  publishActivity(id) {
    return request.put(`/admin/activity/${id}/publish`)
  },
  
  // 取消活动
  cancelActivity(id) {
    return request.put(`/admin/activity/${id}/cancel`)
  },
  
  // 获取活动类型列表
  getActivityTypes() {
    return request.get('/admin/activity/types')
  },
  
  // 获取活动报名列表
  getActivityRegistrations(activityId, params) {
    return request.get(`/admin/activity/${activityId}/registrations`, { params })
  },
  
  // 确认报名
  confirmRegistration(registrationId) {
    return request.put(`/admin/activity/registration/${registrationId}/confirm`)
  },
  
  // 取消报名
  cancelRegistration(registrationId) {
    return request.delete(`/admin/activity/registration/${registrationId}`)
  },
  
  // 拒绝报名
  rejectRegistration(registrationId, reason) {
    return request.put(`/admin/activity/registration/${registrationId}/reject`, null, { params: { reason } })
  },
  
  // 签到
  checkIn(registrationId) {
    return request.put(`/admin/activity/registration/${registrationId}/checkin`)
  },
  
  // 获取活动报名统计
  getRegistrationStatistics(activityId) {
    return request.get(`/admin/activity/${activityId}/registration/statistics`)
  },
  
  // 获取活动统计数据
  getStatistics() {
    return request.get('/admin/activity/statistics')
  },
  
  // 根据类型统计活动数量
  getActivityCountByType() {
    return request.get('/admin/activity/statistics/type')
  },
  
  // 获取重点推荐的活动
  getFeaturedActivities(limit) {
    return request.get('/admin/activity/featured', { params: { limit } })
  },
  
  // 获取即将开始的活动
  getUpcomingActivities(limit) {
    return request.get('/admin/activity/upcoming', { params: { limit } })
  }
}

// 子页面管理相关接口
export const subpageApi = {
  // 分页查询子页面内容列表
  getSubpagePage(params) {
    return request.get('/admin/subpage/page', { params })
  },
  
  // 根据ID获取子页面内容详情
  getSubpageById(id) {
    return request.get(`/admin/subpage/${id}`)
  },
  
  // 根据模块获取子页面内容
  getSubpagesByModule(module) {
    return request.get(`/admin/subpage/module/${module}`)
  },
  
  // 添加子页面内容
  addSubpage(data) {
    return request.post('/admin/subpage', data)
  },
  
  // 更新子页面内容
  updateSubpage(data) {
    return request.put('/admin/subpage', data)
  },
  
  // 删除子页面内容
  deleteSubpage(id) {
    return request.delete(`/admin/subpage/${id}`)
  },
  
  // 批量删除子页面内容
  deleteSubpages(ids) {
    return request.delete('/admin/subpage/batch', { data: ids })
  },
  
  // 更新子页面内容状态
  updateSubpageStatus(id, status) {
    return request.put(`/admin/subpage/${id}/status?status=${status}`)
  },
  
  // 获取子页面统计数据
  getStatistics() {
    return request.get('/admin/subpage/statistics')
  },
  
  // 根据页面类型获取子页面列表
  getSubpageList(pageKey, sectionKey) {
    return request.get(`/admin/subpage/list/${pageKey}/${sectionKey}`)
  },
  
  // 根据页面类型和section获取子页面内容
  getSubpageByKey(pageKey, sectionKey) {
    return request.get(`/admin/subpage/${pageKey}/${sectionKey}`)
  }
}

// 审核管理相关接口
export const approvalApi = {
  // 获取展商审核列表
  getExhibitorApprovals(params) {
    return request.get('/admin/approval/exhibitors', { params })
  },
  
  // 审核展商申请
  approveExhibitor(id, status, comment, auditUser) {
    return request.put(`/admin/approval/exhibitor/${id}`, null, {
      params: { status, comment, auditUser }
    })
  },
  
  // 获取观众审核列表
  getVisitorApprovals(params) {
    return request.get('/admin/approval/visitors', { params })
  },
  
  // 审核观众申请
  approveVisitor(id, status, comment, auditUser) {
    return request.put(`/admin/approval/visitor/${id}`, null, {
      params: { status, comment, auditUser }
    })
  },
  
  // 获取媒体审核列表
  getMediaApprovals(params) {
    return request.get('/admin/approval/media', { params })
  },
  
  // 审核媒体申请
  approveMedia(id, status, comment, auditUser) {
    return request.put(`/admin/approval/media/${id}`, null, {
      params: { status, comment, auditUser }
    })
  },
  
  // 获取签证审核列表
  getVisaApprovals(params) {
    return request.get('/admin/approval/visa', { params })
  },
  
  // 审核签证申请
  approveVisa(id, status, comment, auditUser) {
    return request.put(`/admin/approval/visa/${id}`, null, {
      params: { status, comment, auditUser }
    })
  },
  
  // 获取票务审核列表
  getTicketApprovals(params) {
    return request.get('/admin/approval/tickets', { params })
  },
  
  // 审核票务订单
  approveTicket(id, status, comment, auditUser) {
    return request.put(`/admin/approval/ticket/${id}`, null, {
      params: { status, comment, auditUser }
    })
  },
  
  // 获取审核统计数据
  getApprovalStatistics() {
    return request.get('/admin/approval/statistics')
  },
  
  // 分页获取所有审核数据
  getApprovalPage(params) {
    return request.get('/admin/approval/page', { params })
  },
  
  // 批量审核
  batchApprove(ids, status, comment, auditUser) {
    return request.put('/admin/approval/batch', null, {
      params: { ids: ids.join(','), status, comment, auditUser }
    })
  }
}

// 媒体管理相关接口
export const mediaApi = {
  // 分页查询媒体列表
  getMediaPage(params) {
    return request.get('/admin/media/page', { params })
  },
  
  // 根据ID获取媒体详情
  getMediaById(id) {
    return request.get(`/admin/media/${id}`)
  },
  
  // 添加媒体
  addMedia(data) {
    return request.post('/admin/media', data)
  },
  
  // 更新媒体信息
  updateMedia(data) {
    return request.put('/admin/media', data)
  },
  
  // 删除媒体
  deleteMedia(id) {
    return request.delete(`/admin/media/${id}`)
  },
  
  // 批量删除媒体
  deleteMedias(ids) {
    return request.delete('/admin/media/batch', { data: ids })
  },
  
  // 更新媒体状态
  updateMediaStatus(id, status) {
    return request.put(`/admin/media/${id}/status?status=${status}`)
  },
  
  // 分页查询媒体内容列表
  getMediaContentPage(params) {
    return request.get('/admin/media/content/page', { params })
  },
  
  // 添加媒体内容
  addMediaContent(data) {
    return request.post('/admin/media/content', data)
  },
  
  // 更新媒体内容
  updateMediaContent(data) {
    return request.put('/admin/media/content', data)
  },
  
  // 删除媒体内容
  deleteMediaContent(id) {
    return request.delete(`/admin/media/content/${id}`)
  },
  
  // 分页查询媒体注册列表
  getMediaRegistrationPage(params) {
    return request.get('/admin/media/registration/page', { params })
  },
  
  // 审核媒体注册
  auditMediaRegistration(id, status, comment, auditUser) {
    return request.put(`/admin/media/registration/${id}/audit`, null, {
      params: { status, comment, auditUser }
    })
  },
  
  // 获取媒体统计数据
  getStatistics() {
    return request.get('/admin/media/statistics')
  },
  
  // 获取推荐媒体内容
  getFeaturedMedia(limit) {
    return request.get('/admin/media/featured', { params: { limit } })
  }
}

// 下载管理相关接口
export const downloadApi = {
  // 分页查询下载文件列表
  getDownloadPage(params) {
    return request.get('/admin/download/page', { params })
  },
  
  // 根据ID获取下载文件详情
  getDownloadById(id) {
    return request.get(`/admin/download/${id}`)
  },
  
  // 根据分类获取下载文件
  getDownloadsByCategory(category) {
    return request.get(`/admin/download/category/${category}`)
  },
  
  // 添加下载文件
  addDownload(data) {
    return request.post('/admin/download', data)
  },
  
  // 更新下载文件信息
  updateDownload(data) {
    return request.put('/admin/download', data)
  },
  
  // 删除下载文件
  deleteDownload(id) {
    return request.delete(`/admin/download/${id}`)
  },
  
  // 批量删除下载文件
  deleteDownloads(ids) {
    return request.delete('/admin/download/batch', { data: ids })
  },
  
  // 更新下载文件状态
  updateDownloadStatus(id, status) {
    return request.put(`/admin/download/${id}/status?status=${status}`)
  },
  
  // 增加下载次数
  incrementDownloadCount(id) {
    return request.put(`/admin/download/${id}/increment-download`)
  },
  
  // 获取下载统计数据
  getStatistics() {
    return request.get('/admin/download/statistics')
  },
  
  // 获取热门下载文件
  getPopularDownloads(limit) {
    return request.get('/admin/download/popular', { params: { limit } })
  },
  
  // 获取最新下载文件
  getRecentDownloads(limit) {
    return request.get('/admin/download/recent', { params: { limit } })
  }
}

// 系统管理相关接口
export const systemApi = {
  // 用户管理
  getUserPage(params) {
    return request.get('/admin/system/user/page', { params })
  },
  
  addUser(data) {
    return request.post('/admin/system/user', data)
  },
  
  updateUser(data) {
    return request.put('/admin/system/user', data)
  },
  
  deleteUser(userId) {
    return request.delete(`/admin/system/user/${userId}`)
  },
  
  updateUserStatus(userId, status) {
    return request.put(`/admin/system/user/${userId}/status?status=${status}`)
  },
  
  // 角色管理
  getRolePage(params) {
    return request.get('/admin/system/role/page', { params })
  },
  
  getAllRoles() {
    return request.get('/admin/system/role/all')
  },
  
  addRole(data) {
    return request.post('/admin/system/role', data)
  },
  
  updateRole(data) {
    return request.put('/admin/system/role', data)
  },
  
  deleteRole(roleId) {
    return request.delete(`/admin/system/role/${roleId}`)
  },
  
  // 菜单管理
  getMenuList() {
    return request.get('/admin/system/menu/list')
  },
  
  addMenu(data) {
    return request.post('/admin/system/menu', data)
  },
  
  updateMenu(data) {
    return request.put('/admin/system/menu', data)
  },
  
  deleteMenu(id) {
    return request.delete(`/admin/system/menu/${id}`)
  },

  // 资源管理
  getResourceTree() {
    return request.get('/admin/system/resource/tree')
  },
  
  addResource(data) {
    return request.post('/admin/system/resource', data)
  },
  
  // 用户角色关系管理
  assignUserRole(data) {
    return request.post('/admin/system/user-role', data)
  },
  
  removeUserRole(relationId) {
    return request.delete(`/admin/system/user-role/${relationId}`)
  },
  
  getUserRoles(userId) {
    return request.get(`/admin/system/user/${userId}/roles`)
  },
  
  // 角色资源关系管理
  assignRoleResource(data) {
    return request.post('/admin/system/role-resource', data)
  },
  
  getRoleResources(roleCode) {
    return request.get(`/admin/system/role/${roleCode}/resources`)
  },
  
  // 系统设置管理
  getAllSettings() {
    return request.get('/admin/system/setting/all')
  },
  
  getSettingByKey(key) {
    return request.get(`/admin/system/setting/${key}`)
  },
  
  addSetting(data) {
    return request.post('/admin/system/setting', data)
  },
  
  updateSetting(data) {
    return request.put('/admin/system/setting', data)
  },
  
  deleteSetting(id) {
    return request.delete(`/admin/system/setting/${id}`)
  },
  
  
  // 获取所有系统设置
  getAllSettings() {
    return request.get('/admin/system/setting/all')
  },
  
  // 添加系统设置
  addSetting(data) {
    return request.post('/admin/system/setting', data)
  },
  
  // 更新系统设置
  updateSetting(data) {
    return request.put('/admin/system/setting', data)
  },
  
  // 获取系统统计数据
  getSystemStatistics() {
    return request.get('/admin/system/statistics')
  },
  
  // 页脚配置管理
  getFooterLinks() {
    return request.get('/admin/system/footer-links')
  },
  
  updateFooterLinks(data) {
    return request.post('/admin/system/footer-links', data)
  },
  
  getPrivacyPolicy() {
    return request.get('/admin/system/privacy-policy')
  },
  
  updatePrivacyPolicy(data) {
    return request.post('/admin/system/privacy-policy', data)
  },
  
  getTermsOfService() {
    return request.get('/admin/system/terms-of-service')
  },
  
  updateTermsOfService(data) {
    return request.post('/admin/system/terms-of-service', data)
  },

  // 参观条款
  getVisitorTerms() {
    return request.get('/admin/system/visitor-terms')
  },

  updateVisitorTerms(data) {
    return request.post('/admin/system/visitor-terms', data)
  },

  // 参观隐私政策
  getVisitorPrivacyPolicy() {
    return request.get('/admin/system/visitor-privacy-policy')
  },

  updateVisitorPrivacyPolicy(data) {
    return request.post('/admin/system/visitor-privacy-policy', data)
  },

  // 底部隐私政策
  getFooterPrivacyPolicy() {
    return request.get('/admin/system/footer-privacy-policy')
  },

  updateFooterPrivacyPolicy(data) {
    return request.post('/admin/system/footer-privacy-policy', data)
  },

  // 底部服务条款
  getFooterTermsOfService() {
    return request.get('/admin/system/footer-terms-of-service')
  },

  updateFooterTermsOfService(data) {
    return request.post('/admin/system/footer-terms-of-service', data)
  }
}

// 签证管理相关接口
export const visaApi = {
  // 获取签证申请分页数据
  getVisaPage(params) {
    return request.get('/admin/visa/page', { params })
  },
  
  // 添加签证申请
  addVisa(data) {
    return request.post('/admin/visa/add', data)
  },
  
  // 更新签证申请
  updateVisa(data) {
    return request.post('/admin/visa/update', data)
  },
  
  // 删除签证申请
  deleteVisa(id) {
    return request.post(`/admin/visa/delete/${id}`)
  },
  
  // 审核签证申请
  auditVisa(data) {
    const id = data?.id
    const status = data?.status
    const auditComment = data?.auditComment || ''
    const auditUser = data?.auditUser
    return request.post(`/admin/visa/audit?id=${id}&status=${encodeURIComponent(status)}&auditComment=${encodeURIComponent(auditComment)}&auditUser=${encodeURIComponent(auditUser)}`)
  }
}

// 票务管理相关接口
export const ticketApi = {
  // 获取票务信息分页数据
  getTicketPage(params) {
    return request.get('/admin/ticket/page', { params })
  },
  
  // 添加票务信息
  addTicket(data) {
    return request.post('/admin/ticket/add', data)
  },
  
  // 更新票务信息
  updateTicket(data) {
    return request.post('/admin/ticket/update', data)
  },
  
  // 删除票务信息
  deleteTicket(id) {
    return request.post(`/admin/ticket/delete/${id}`)
  },
  
  // 审核票务信息
  auditTicket(data) {
    return request.post('/admin/ticket/audit', data)
  },
  
  // 审核票务信息（使用RequestParam）
  auditTicketWithParams(params) {
    return request.post('/admin/ticket/audit', null, { params })
  }
}

// 用户管理相关接口
export const userApi = {
  // 分页查询用户列表
  getUserPage(params) {
    return request.get('/admin/user/page', { params })
  },
  
  // 获取用户详情
  getUserById(id) {
    return request.get(`/admin/user/${id}`)
  },
  
  // 添加用户
  addUser(data) {
    return request.post('/admin/user', data)
  },
  
  // 更新用户信息
  updateUser(data) {
    return request.put('/admin/user', data)
  },
  
  // 删除用户
  deleteUser(id) {
    return request.delete(`/admin/user/${id}`)
  },
  
  // 更新用户状态
  updateUserStatus(id, status) {
    return request.put(`/admin/user/${id}/status`, { status })
  },
  
  // 获取用户统计数据
  getUserStatistics() {
    return request.get('/admin/user/statistics')
  }
}

// 综合API接口
export const adminApi = {
  // 测试API连接
  testConnection() {
    return request.post('/admin/api/test-connection')
  }
}
